// WndOperation.cpp: implementation of the WndOperation class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "WndOperation.h"
#include <Shlwapi.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

WndOperation::WndOperation()
{

}

WndOperation::~WndOperation()
{

}

void WndOperation::DeleteAllItem(CComboBox* pCombo)
{
	ASSERT(pCombo);

	while(pCombo->GetCount() > 0)
	{
		pCombo->DeleteString(0);
	}
}

CString FileSystemOperation::GetFileName(const CString& strFullName)
{
	CString strTemp;
	INT nStart = 0;
	INT nEnd = 0;

	for(int i = strFullName.GetLength() - 1; i >= 0; i--)
	{
		if(strFullName.GetAt(i) == '.')
		{
			nEnd = i;
		}
		else if(strFullName.GetAt(i) == '\\')
		{
			nStart = i + 1;
			break;
		}
	}
	strTemp = strFullName.Mid(nStart, nEnd - nStart);

	return strTemp;
}

CString FileSystemOperation::GetFilePath(const CString& strFullName)
{
	CString strTemp;
	INT nStart = 0;

	for(int i = strFullName.GetLength() - 1; i >= 0; i--)
	{
		if(strFullName.GetAt(i) == '\\')
		{
			nStart = i + 1;
			break;
		}
	}
	strTemp = strFullName.Mid(0, nStart);

	return strTemp;
}

HICON FileSystemOperation::GetFileIcon(const CString& strFullName)
{
	SHFILEINFO stFileInfo;
	DWORD dw;
	
	dw = ::SHGetFileInfo(strFullName,0,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON);
	if( dw == 0 )
		return NULL;
	
	return stFileInfo.hIcon;
}

BOOL FileSystemOperation::IsPathFileExists( const StdString& strPath )
{
	return ::PathFileExists( strPath );
}

BOOL FileSystemOperation::CreateDirectoryUE(const StdString& strPath)
{
	if( strPath.IsEmpty() )
	{
		return FALSE;
	}
	else if( IsPathFileExists( strPath ) )
	{
		return TRUE;
	}
	StdString strTemp = strPath;
	if( strTemp.GetAt( strTemp.GetLength() - 1 ) == '\\' )
	{
		strTemp.Delete( strTemp.GetLength() - 1 );
	}
	while( ( strTemp.GetAt( strTemp.GetLength() - 1 ) != '\\' ) && !strTemp.IsEmpty() )
	{
		strTemp.Delete( strTemp.GetLength() - 1 );
	}
	if ( !CreateDirectoryUE( strTemp ) )
	{
		return FALSE;
	}
	return CreateDirectory( strPath, NULL ) ;
	
	
}